package org.hefan.hrm.controller;

import org.hefan.hrm.doc.CourseDoc;
import org.hefan.hrm.query.CourseDocQuery;
import org.hefan.hrm.repository.CourseDocRepository;
import org.hefan.hrm.service.ICourseDocService;
import org.hefan.hrm.util.AjaxResult;
import org.hefan.hrm.util.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/courseDoc")
public class CourseDocController {

//    @Autowired
//    private CourseDocRepository repository;

    @Autowired
    private ICourseDocService courseDocService;

    /**
     * 批量添加
     */
//    @PostMapping("/add")
//    public AjaxResult batchAdd(@RequestBody List<CourseDoc> courseDocs) {
//        repository.saveAll(courseDocs);
//        return AjaxResult.me();
//    }
    @PostMapping("/add")
    public AjaxResult batchAdd(@RequestBody List<CourseDoc> courseDocs) {
        return courseDocService.batchAdd(courseDocs);
    }

    /**
     * 批量删除
     */
//    @PostMapping("/del")
//    public AjaxResult batchDel(@RequestBody List<Long> ids) {
//        Iterable<CourseDoc> courseDocs = repository.findAllById(ids);
//        repository.deleteAll(courseDocs);
//        return AjaxResult.me();
//    }
    @PostMapping("/del")
    public AjaxResult batchDel(@RequestBody List<Long> ids) {
        return courseDocService.batchDel(ids);
    }

    @PostMapping("/queryCourses")
    public PageList<CourseDoc> queryPageData(@RequestBody CourseDocQuery query) {
        return courseDocService.queryPageData(query);
    }
}
